﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ProductManager_ReturnPrdt : System.Web.UI.Page
{
    GoShopping.BLL.Orders.OrderBean ordBean = new GoShopping.BLL.Orders.OrderBean();
    GoShopping.BLL.Orders.ReturnPrtsRecordsBean returnPrdtBean = new GoShopping.BLL.Orders.ReturnPrtsRecordsBean();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {
                hidOrderId.Value = Request.QueryString["ID"].ToString();
                InitialPage();
            }
        }
    }

    private void InitialPage()
    {
        GetGVPrdts(Convert.ToInt32(hidOrderId.Value));
        GoShopping.Model.Order ord = ordBean.GetOneOrder(Convert.ToInt32(Request.QueryString["ID"]));
        lblRePrdtCode.Text = "";
        lblOrderCode.Text = ord.OrderCode;
        lblOrderDate.Text = ord.OrderCreateDate.ToString();
        lblRePrdtAddr.Text = "售货人地址";
        lblRePrdtCustomer.Text = ord.UserName;
        lblRePrdtDealMan.Text = Context.User.Identity.Name;
        rbYes.Checked = true;//暂无数据
    }

    void GetGVPrdts(int orderId)
    {
        gvRePrdtList.DataSource = ordBean.GetOrderEachPrdct(orderId);
        gvRePrdtList.DataBind();
    }
    protected void btnComplete_Click(object sender, EventArgs e)
    {
        GoShopping.Model.ReturnPrtsRecords rpr = new GoShopping.Model.ReturnPrtsRecords();
        //保存到数据库中
        rpr.OrderID = lblOrderCode.Text;
        rpr.ReturnDate = Convert.ToDateTime(lblOrderDate.Text);
        rpr.ReturnAddress = lblRePrdtAddr.Text;
        rpr.ReturnUser = lblRePrdtCustomer.Text;
        rpr.RecordPerson = lblRePrdtDealMan.Text;
        rpr.IsInsurance = rbYes.Checked;

        rpr.ReturnType = txtReturnType.Text.Trim();
        rpr.Returner = txtCompanyOrCharger.Text;
        rpr.ReturnFee = Convert.ToDecimal(txtRePrdtFee.Text);
        rpr.Remark = txtComment.Text;
        //插入数据
        returnPrdtBean.Insert(rpr);
        //更新订单状态
        ordBean.UpdateOrder(Convert.ToInt32(Request.QueryString["ID"]), GoShopping.Model.Enumerations.OrderStatusType.Returning);
        //跳转到ReturnCashRecords.aspx 退货中,还没有收到货
        Response.Redirect("OrderDetail.aspx?ID=" + Request.QueryString["ID"]);

    }
    protected void gvRePrdtList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //删除操作:
        //1.从该订单中删除该商品
        //2.从订单总金额中减去退货商品金额
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("OrderDetail.aspx?ID=" + hidOrderId.Value);
    }
}
